home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / 3dTruchet.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  7.0 KB  |  232 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ; This program is distributed in the hope that it will be useful,
  9. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ; GNU General Public License for more details.
  12. ; You should have received a copy of the GNU General Public License
  13. ; along with this program; if not, write to the Free Software
  14. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ;
  16. ;    3dTruchet  - a script to create Truchet patterns 
  17. ;                 by Adrian Likins <aklikins@eos.ncsu.edu>
  18. ;                 http://www4.ncsu.edu/~aklikins/
  19. ;    version about .8 give or take
  20. ;
  21. ;  Lots of thanks to Quartic for his help.
  22. ;
  23. ;
  24. ;         The utility of this script is left as an exercise for the reader.
  25.  
  26. (define (center-ellipse img
  27.             cx
  28.             cy
  29.             rx
  30.             ry
  31.             op
  32.             aa
  33.             feather
  34.             frad)
  35.   (gimp-ellipse-select img (- cx rx) (- cy ry) (+ rx rx) (+ ry ry)
  36.                op aa feather frad))
  37.  
  38. (define (use-tile img
  39.           drawable
  40.           height
  41.           width
  42.           img2
  43.           drawable2
  44.           xoffset
  45.           yoffset)
  46.   (gimp-edit-copy drawable2)
  47.   (let ((floating-sel (car (gimp-edit-paste drawable FALSE))))
  48.     (gimp-layer-set-offsets floating-sel xoffset yoffset)
  49.     (gimp-floating-sel-anchor floating-sel)
  50.     )
  51.   )
  52.  
  53.  
  54. (define (create-tile img
  55.              drawable1
  56.              drawable2
  57.              size
  58.              thickness
  59.              backcolor
  60.              begincolor
  61.              endcolor
  62.              supersample)
  63.   (let* (
  64.      (half-thickness (/ thickness 2))
  65.      (outer-radius (+ (/ size 2) half-thickness))
  66.      (inner-radius (- (/ size 2) half-thickness))
  67.      )
  68.  
  69.     (gimp-selection-all img)
  70.     (gimp-context-set-background backcolor)
  71.     (gimp-edit-fill drawable1 BACKGROUND-FILL)
  72.  
  73.     (let* (
  74.        (tempSize (* size 3))
  75.        (temp-img (car (gimp-image-new tempSize tempSize RGB)))
  76.        (temp-draw (car (gimp-layer-new temp-img tempSize tempSize
  77.                        RGB-IMAGE "Jabar" 100 NORMAL-MODE)))
  78.              (temp-draw2 (car (gimp-layer-new temp-img tempSize tempSize
  79.                         RGB-IMAGE "Jabar" 100 NORMAL-MODE))))
  80.  
  81.       (gimp-image-undo-disable temp-img)
  82.       (gimp-image-add-layer temp-img temp-draw 0)
  83.       (gimp-image-add-layer temp-img temp-draw2 0)
  84.       (gimp-context-set-background backcolor)
  85.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  86.       (gimp-edit-fill temp-draw2 BACKGROUND-FILL)
  87.  
  88.       ;weird aint it
  89.       (gimp-context-set-background begincolor)
  90.       (gimp-context-set-foreground endcolor)
  91.  
  92.       (center-ellipse temp-img size size outer-radius outer-radius
  93.               CHANNEL-OP-REPLACE TRUE FALSE 0)
  94.       (center-ellipse temp-img size size inner-radius inner-radius
  95.               CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  96.       
  97.       (center-ellipse temp-img (* size 2) (*  size 2)  outer-radius outer-radius
  98.               CHANNEL-OP-ADD TRUE FALSE 0)
  99.       (center-ellipse temp-img (* size 2) (*  size 2)  inner-radius inner-radius
  100.               CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  101.  
  102.       (gimp-edit-blend temp-draw FG-BG-RGB-MODE NORMAL-MODE
  103.                GRADIENT-SHAPEBURST-ANGULAR 100 0 REPEAT-NONE FALSE
  104.                supersample 3 .2 TRUE
  105.                size size (* size 2) (/ size 2))
  106.  
  107.       (center-ellipse temp-img size (* size 2)  outer-radius outer-radius
  108.               CHANNEL-OP-REPLACE TRUE FALSE 0)
  109.       (center-ellipse temp-img size (* size 2) inner-radius inner-radius
  110.               CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  111.  
  112.       (center-ellipse temp-img (* size 2) size  outer-radius outer-radius
  113.               CHANNEL-OP-ADD TRUE FALSE 0)
  114.       (center-ellipse temp-img (* size 2) size  inner-radius inner-radius
  115.               CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  116.  
  117.       ;(gimp-edit-fill temp-img temp-draw2 BACKGROUND-FILL)
  118.  
  119.       (gimp-edit-blend temp-draw2 FG-BG-RGB-MODE NORMAL-MODE
  120.                GRADIENT-SHAPEBURST-ANGULAR 100 0 REPEAT-NONE FALSE
  121.                supersample 3 .2 TRUE
  122.                size size (* size 2) (* size 2))
  123.  
  124.       (gimp-selection-none temp-img)
  125.  
  126.       (gimp-image-resize temp-img size size (- size) (- size))
  127.       ; woo hoo it works....finally...
  128.  
  129.  
  130.       (gimp-selection-all temp-img)
  131.       (gimp-edit-copy temp-draw)
  132.       (let ((floating-sel (car (gimp-edit-paste drawable2 FALSE))))
  133.     (gimp-floating-sel-anchor floating-sel))
  134.  
  135.       (gimp-edit-copy temp-draw2)
  136.       (let ((floating-sel (car (gimp-edit-paste drawable1 FALSE))))
  137.     (gimp-floating-sel-anchor floating-sel))
  138.  
  139.       ;(let ((drawble (car (gimp-drawable-transform-flip-simple img drawable1
  140.       ;                        ORIENTATION-HORIZONTAL
  141.       ;                        TRUE 0 TRUE)))))
  142.     
  143.  
  144.       ;(gimp-display-new temp-img)
  145.       (gimp-image-delete temp-img)
  146.       )
  147.     )
  148.   )
  149.  
  150.  
  151. (define (script-fu-3dtruchet size
  152.                  thickness
  153.                  backcolor
  154.                  begincolor
  155.                  endcolor
  156.                  supersample
  157.                  xtiles
  158.                  ytiles)
  159.   (let* (
  160.      (width (* size xtiles))
  161.      (height (* size ytiles))
  162.      (img (car (gimp-image-new width height RGB)))
  163.      (tile (car (gimp-image-new size size RGB)))
  164.      (layer-one (car (gimp-layer-new img width height
  165.                      RGB-IMAGE "Rambis" 100 NORMAL-MODE)))
  166.      (tiledraw1 (car (gimp-layer-new tile size size
  167.                      RGB-IMAGE "Johnson" 100 NORMAL-MODE)))
  168.      (tiledraw2 (car (gimp-layer-new tile size size
  169.                      RGB-IMAGE "Cooper" 100 NORMAL-MODE)))
  170.      (Xindex 0)
  171.      (Yindex 0))
  172.  
  173.     (gimp-context-push)
  174.  
  175.     (gimp-image-undo-disable img)
  176.     (gimp-image-undo-disable tile)
  177.  
  178.     (gimp-image-add-layer img layer-one 0)
  179.     (gimp-image-add-layer tile tiledraw1 0)
  180.     (gimp-image-add-layer tile tiledraw2 0)
  181.  
  182.     ;just to look a little better
  183.     (gimp-selection-all img)
  184.     (gimp-context-set-background backcolor)
  185.     (gimp-edit-fill layer-one BACKGROUND-FILL)
  186.     (gimp-selection-none img)
  187.  
  188.     (create-tile tile tiledraw1 tiledraw2 size thickness
  189.          backcolor begincolor endcolor supersample)
  190.     
  191.  
  192.     (while (<= Xindex xtiles)
  193.        (while (<= Yindex ytiles)
  194.           (if (= (rand 2) 0)
  195.               (use-tile img layer-one height width tile
  196.                 tiledraw1 (* Xindex size) (* Yindex size))
  197.               (use-tile img layer-one height width tile
  198.                 tiledraw2 (* Xindex size) (* Yindex size))
  199.               )
  200.           (set! Yindex (+ Yindex 1))
  201.           )
  202.        (set! Yindex 0)
  203.        (set! Xindex (+ Xindex 1))
  204.        )
  205.  
  206.     (gimp-image-delete tile)
  207.     (gimp-image-undo-enable img)
  208.     (gimp-display-new img)
  209.  
  210.     (gimp-context-pop)))
  211.  
  212. (script-fu-register "script-fu-3dtruchet"
  213.             _"3_D Truchet..."
  214.             "3D Truchet pattern"
  215.             "Adrian Likins <aklikins@eos.ncsu.edu>"
  216.             "Adrian Likins"
  217.             "1997"
  218.             ""
  219.             SF-ADJUSTMENT _"Block size"        '(64 5 1000 1 10 0 1)
  220.             SF-ADJUSTMENT _"Thickness"         '(12 2 100 1 10 0 1)
  221.             SF-COLOR      _"Background color"  '(255 255 255)
  222.             SF-COLOR      _"Start blend"       '(0 0 0)
  223.             SF-COLOR      _"End blend"         '(255 255 255)
  224.             SF-TOGGLE     _"Supersample"       TRUE
  225.             SF-ADJUSTMENT _"Number of X tiles" '(5 1 1000 1 10 0 1)
  226.             SF-ADJUSTMENT _"Number of Y tiles" '(5 1 1000 1 10 0 1))
  227.  
  228. (script-fu-menu-register "script-fu-3dtruchet"
  229.              _"<Toolbox>/Xtns/Script-Fu/Patterns")
  230.